package com.example.demo.lianxi;

import java.util.ArrayList;

public class DotCom {
    /*
    private ArrayList<String> locationCells;
    private String name;
    public void setLocationCells(int[] loc){
        locationCells=loc;

    }
    public void setName(String n){
        name=n;
        }
    public String checkYourself(String userInput){
        String result = "miss";
        int index=locationCells.indexOf(userInput);
        if(index>=0){
            locationCells.remove(index);
            if(locationCells.isEmpty()){
            result="kill";
            System.out.println("ooch! you sunk "+name+":(");
        }else {
                result="hit";

            }
            }return result;
        }


     */


/*第二版
    private ArrayList<String> locationCells;
    public void setLocationCells(ArrayList<String> locs){
        locationCells=locs;
    }
    public String checkYourself(String userInput) {

        String result = "miss";
        int index=locationCells.indexOf(userInput);
       if(index>=0){
           locationCells.indexOf(userInput);

       if(locationCells.isEmpty()){
           result="kill";
       }else{
           result="hit";
       }
       }
        System.out.println(result);
        return result;
    }

 */

/*第一版
   int[] locationCells;
   int numOfHits=0;

   public void setLocationCells(int[] locs){
        locationCells=locs;
    }

    public String checkYourself(String stringGuess){
        int guess=Integer.parseInt(stringGuess);
        String result="miss";
        for (int cell:locationCells){
            if(guess==cell){
                result="hit";
                numOfHits++;
                break;
            }
        }

        if(numOfHits==locationCells.length){
            result="kill";
        }
        System.out.println(result);
        return result;
    }

 */

}
